/*
 * Geometry.java
 *
 * Created on 27 December 2007, 12:06
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package hextd.util;

import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author hylke
 */
public class Geometry {
    /* top-middle
     * top-right
     * bottom-right
     * bottom-middle
     * bottom-left
     * top-left
     */
    
    public static Ellipse2D createCircle(float x, float y, float r) {
        return new Ellipse2D.Float(x-r, y-r, r*2, r*2);
    }
    
    public static float[][] createPolyCoords(float scale, float x, float y) {
        float width = (float)Math.sin(Math.PI/3) * scale;
        float[][] points = {
            {x+0    , y-scale},
            {x+width, y-scale/2},
            {x+width, y+scale/2},
            {x+0    , y+scale},
            {x-width, y+scale/2},
            {x-width, y-scale/2}};
        return points;
    }
    
    public static float[][] createPolyCoords(float scale) {
        return createPolyCoords(scale, 0, 0);
    }
    
    public static GeneralPath coordsToGeneralPath(float[][] points, boolean closed) {
        GeneralPath poly = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
        poly.moveTo(points[0][0], points[0][1]);
        for (int index = 1; index < points.length; index++) {
            poly.lineTo(points[index][0], points[index][1]);
        };
        if (closed) {
            poly.closePath();
        }
        return poly;
    }
}
